home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
001-025
/
scopedisk8
/
asm
/
echo.asm
< prev
next >
Wrap
Assembly Source File
|
1995-03-18
|
8KB
|
197 lines
;
; Yet another ECHO .. Jim Butterfield, 1988Apr2
;
;- This is a CLI command only. Replaces ECHO 1.3 with NOLINE feature.
;- Usage: Echo [NOLINE] <string> ..or.. <string> [NoLine]
;
;- Quotes (") around the argument <string> are unnecessary
; unless you wish to have leading spaces or to type NOLINE,
; for example: Echo " Never say NoLine"
;
;- Asterisks are handled as follows:
; *n or *N - outputs a Newline (linefeed);
; *e or *E - outputs an Escape (chr${27});
; *[anything else] prints the character after asterisk,
; in particular:
; ** - outputs an asterisk;
; *" - outputs quotes (");
; Example: Echo Input**Output 2 3 4
; displays: Input*Output 2 3 4
; === Register Usage (* = used in system calls) ===
; *A0 - general pointer *D0 - general byte buffer
; *A1 - otherwise unused *D1 - otherwise unused
; A2 - output buf scan *D2 - output buf pointer
; A3 - input buf pointer *D3 - output length
; A4 - input scan ptr D4 - LINK pointer
; A5 - main scan ptr D5 - NOLINE flag
; A6 - library pointer D6 - asterisk flag, buffer
; A7 - gosh, I forget D7 - DOS output handle
;-- Symbolic equates:
AbsExecBase equ $4 ; Loc of ptr to the
; Exec library.
LF equ 10 ; Line Feed value.
SPACE equ 32 ; Space char
CASEmask equ %01011111 ; Mask to kill lower case.
;
xref _LVOOpenLibrary ; These are Library routines referenced
xref _LVOCloseLibrary ; externally by this program.
xref _LVOOutput
xref _LVOWrite
xref _LVOInput
xref _LVORead
;
; Save pointer and open DOS
_main moveq #0,d5 ; clear noline flag
move.l a0,a3 ; pointer, input-buffer
move.l a0,a5 ; work pointer
lea dosname(pc),a1
clr d0 ; Any version
move.l AbsExecBase,a6
jsr _LVOOpenLibrary(a6) ;Open Dos library.
move.l d0,a6 ; Remember dosbase ptr.
beq quit
;
;-- Get CLI outhandle:
jsr _LVOOutput(a6) ; get CLI outhandle,
move.l d0,d7 ; & then remember it.
; grab stack space
link a4,#-$100
move.l a4,d4
move.l a7,a2 ; pointer, output-buffer
; Check for ? sequence
qspace move.l a5,a4
cmp.b #SPACE,(a5)+
beq.s qspace
move.l a4,a5
cmp.b #$3F,(a4)+
bne.s ljob
cmp.b #LF,(a4)
bne.s ljob
; Do the prompt thing
lea template(pc),a0
move.l a0,d2
move.l d7,d1
move.l #templen,d3
jsr _LVOWrite(a6)
jsr _LVOInput(a6)
move.l d0,d1
move.l a2,a3 ; switch input-buffer
move.l a3,d2
move.l #255,d3
jsr _LVORead(a6)
; Scan leading spaces and mebbe NOLINE
;
ljob move.l a3,a5 ; input-buffer pointer
lspace move.l a5,a4 ; first non-space
cmp.b #SPACE,(a5)+
beq.s lspace ; space .. correct it
move.l a4,a5
tst.b d5 ; if we've found NOLINE..
bne.s nonoline1 ; ..don't search again
; search for NOLINE <space> at start
lea nolnstr(pc),a0
nolinecklp move.b (a4)+,d0 ; text char
andi.b #CASEmask,d0
cmp.b (a0)+,d0 ; NOLINE mask char
bne.s nonoline1
tst.b d0 ; <space> becomes $0
bne.s nolinecklp ; if not space, back
; found NOLINE <space>
moveq #1,d5 ; set NOLINE flag
move.l a4,a5
bra.s lspace ; trim extra spaces
; scan to end of input, trim end spaces
nonoline1 move.l a5,a4
findend cmpi.b #LF,(a4)+ ; search for LF
bne.s findend
espace move.b #0,-(a4) ; change end to $0
move.l a4,a0
cmp.b #SPACE,-(a0)
beq.s espace ; back through spaces
tst.b d5 ; if we've found NOLINE..
bne.s nonoline2 ; ..don't search again
; search for <space>NOLINE at end
lea nolnstrend(pc),a0
nolckloop move.b -(a4),d0 ; text char
andi.b #CASEmask,d0
cmp.b -(a0),d0 ; NOLINE mask char
bne.s nonoline2
tst.b d0 ; <space> has become $0
bne.s nolckloop ; not space, try more.
moveq #1,d5 ; set NOLINE flag.
addq.l #1,a4
bra.s espace ; back to kill space(s).
;
;-- Start the argument line scanning process:
nonoline2 clr.l d3 ; Clear output-chars count.
clr.b d6 ; Clear asterisk flag.
move.l a2,d2
;
;-- Make new output line from argument line:
scan move.b (a5)+,d0 ; Get argument char.
beq exit ; Zero means we're finsihed.
;
;-- Check special chars flag:
tst.b d6 ; Check asterisk flag.
beq.s noastrsk ; No asterisk? Skip.
;
;-- Handle asterisk-plus-char:
move.b d0,d6
andi.b #CASEmask,d6 ; Kill lower case.
cmpi.b #69,d6 ; Test for E
bne.s try2
move.b #27,d0 ; E, substitute ESC
try2 cmpi.b #78,d6 ; Test for N
bne.s putinbuf
move.b #LF,d0 ; N, substitute Newline
;
;-- Check for quote:
noastrsk cmpi.b #'"',d0 ; If char is quote,
beq.s scan ; skip it.
;
;-- Check for asterisk:
moveq #1,d6
cmpi.b #'*',d0 ; Is it '*'?
beq.s scan ; Yes, log and get next char
;
;-- Put char in buffer:
putinbuf clr.b d6 ; Clear Asterisk flag
move.b d0,(a2)+ ; Put char to output buffer.
addq.b #1,d3 ; Increment outchar count.
bra.s scan ; Go for more input.
;
;-- After looking at all argument chars:
exit tst.b d5 ; Check NOLINE flag.
bne.s nolf
move.b #LF,(a2)+ ; If it's 0, put a linefeed at end.
addq.b #1,d3 ; & increment count to handle it.
nolf tst.b d3
beq close
; D2 and D3 already contain buffer address and size
move.l d7,d1 ; Outhandle
jsr _LVOWrite(a6) ; Print it!
;
;-- Unlink and close opened libraries:
close move.l d4,a4
unlk a4
move.l a6,a1 ; DOSBase to A1
move.l AbsExecBase,a6 ; Exec library...
jsr _LVOCloseLibrary(a6) ; close Dos library.
quit rts ; Return control to CLI.
;
;-- Dos Library name:
dosname dc.b 'dos.library',0 ;name of Dos library
;-- NoLine keyword
dc.b 0
nolnstr dc.b 'NOLINE'
nolnstrend equ *
dc.b 0
;-- Template string:
template dc.b 'STRING,NOLINE/S: '
endtemp:
templen EQU endtemp-template
end